import JSEncrypt from 'jsencrypt'
import Vue from 'vue'
// 密钥对生成 http://web.chacuo.net/netrsakeypair

const publicKey = 'MIGfMA0GCSqGSIb3DQEBAQUAA4GNADCBiQKBgQDDVMn8WbNWbQLIYX6CGGYVp42pbgxke4WdTV9dgnCl1YvVoQ8zN/jvC0IjAzGczdrhoV0fpY06YT6R8GdeX9ABABHqs8/OvVEHVspyKYHzgVYxBA0ZKv6KZ3aW797qN0tURPlEHytjvbY4wvYtmwjlLd2WQQort6Rm8lxiKc3TVQIDAQAB'

const privateKey = 'MIICdgIBADANBgkqhkiG9w0BAQEFAASCAmAwggJcAgEAAoGBAMNUyfxZs1ZtAshhfoIYZhWnjaluDGR7hZ1NX12CcKXVi9WhDzM3+O8LQiMDMZzN2uGhXR+ljTphPpHwZ15f0AEAEeqzz869UQdWynIpgfOBVjEEDRkq/opndpbv3uo3S1RE+UQfK2O9tjjC9i2bCOUt3ZZBCiu3pGbyXGIpzdNVAgMBAAECgYEAiz3gFvHis9NVzn4hbp/x9bHRfFwknWSoZPAI8WHQ54aI/iqn6T0XSWBfLxJRxZPBWmJrPeoH+PvlXKdhKJdocG2D6dJMo+deQnrlU+YhYgd1PLm2tLiyhJr3gxkp2PL1KSHJtiLQ6dMpnNwDW35OjFLLMdLwF8k9DQozACNnvcECQQD4d44+AKdqxDyQS7Dj85rTZaA1kypBPT7AcjUEOt0/bfMncj9hcyhXFt3PNrAYUOTByhGK8mz7b3q+WSHSKb65AkEAyUDTpGfqSid5OGhtJoizkmcfhnci3/CLkf8T6z247WXgu2dNcVO7J2PVtcshv+ebEAJaRqAby32PU5u8+yfLfQJAVGeQu4FPXhaRmFcOHTGo270/IlP+27Cpe4iQeAJjHGQGYNUPsNQE1Sjgar7iLTB1tVsmgHQAD538LWNr+M/TiQJAHOlyPjEriGGpWYAvBhUnbwXfkoq0+OTuuBej/eyND5XONj398yTrQxpljktTWuVj8mXUIEdKFu6/02wRNyedZQJAWr8jAZ18rJSNjPgUhQc70PKTUo0DtkYXMrKtuStPMEXX40oSmihYkNVedwH4+jtijtVG1mYvXNiKAU3GDnsU2w=='

// 加密
export function encrypt(txt) {
  const encryptor = new JSEncrypt()
  encryptor.setPublicKey(publicKey) // 设置公钥
  return encryptor.encrypt(txt) // 对需要加密的数据进行加密
}

// 解密
export function decrypt(txt) {
  const encryptor = new JSEncrypt()
  encryptor.setPrivateKey(privateKey)
  return encryptor.decrypt(txt)
}
Vue.prototype.$encrypt = function(txt) {
  const encryptor = new JSEncrypt()
  encryptor.setPublicKey(publicKey) // 设置公钥
  return encryptor.encrypt(txt) // 对需要加密的数据进行加密
}
